package com.arui.yygh.order.api;

import com.arui.yygh.common.result.Result;
import com.arui.yygh.common.utils.AuthContextHolder;
import com.arui.yygh.enums.OrderStatusEnum;
import com.arui.yygh.model.order.OrderInfo;
import com.arui.yygh.model.user.UserInfo;
import com.arui.yygh.order.service.OrderService;
import com.arui.yygh.vo.order.OrderCountQueryVo;
import com.arui.yygh.vo.order.OrderQueryVo;
import com.arui.yygh.vo.user.UserInfoQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderApiController {

    @Autowired
    private OrderService orderService;

    //创建订单
    @ApiOperation(value = "创建订单")
    @PostMapping("auth/submitOrder/{scheduleId}/{patientId}")
    public Result saveOrders(@PathVariable String scheduleId,
                             @PathVariable Long patientId) {
        return Result.ok(orderService.saveOrder(scheduleId, patientId));
    }
    //根据订单id查询订单详情信息
    @GetMapping("/auth/getOrders/{orderId}")
    public Result getOrders(@PathVariable String orderId){
        OrderInfo orderInfo = orderService.getOrder(orderId);

        return Result.ok(orderInfo);

    }
    //订单列表(条件查询带分页)
    @GetMapping("auth/{page}/{limit}")
    public Result list(@PathVariable Long page, @PathVariable Long limit, OrderQueryVo orderQueryVo, HttpServletRequest request){
        Page<OrderInfo> pageParam = new Page<>(page,limit);
        //设置当前用户id值
        orderQueryVo.setUserId(AuthContextHolder.getUserId(request));
        IPage<OrderInfo> pageModel = orderService.selectPage(pageParam,orderQueryVo);

        return Result.ok(pageModel);

    }
    //查询所有订单状态
    @ApiOperation(value = "获取订单状态")
    @GetMapping("/auth/getStatusList")
    public Result getStatusList() {
        return Result.ok(OrderStatusEnum.getStatusList());
    }
    //取消预约
    @GetMapping("/auth/cancelOrder/{orderId}")
    public Result cancelOrder(@PathVariable Long orderId){
        Boolean isOrder = orderService.cancelOrder(orderId);
        return Result.ok(isOrder);
    }
    @ApiOperation(value = "获取订单统计数据")
    @PostMapping("/inner/getCountMap")
    public Map<String, Object> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo) {
        return orderService.getCountMap(orderCountQueryVo);
    }


}
